package com.gel.codegeneration.core.saver;

import cn.hutool.core.util.StrUtil;
import com.gel.codegeneration.ai.model.entity.HtmlCodeResult;
import com.gel.codegeneration.ai.model.enums.CodeGenTypeEnum;

import com.gel.codegeneration.common.enums.ErrorCode;
import com.gel.codegeneration.convention.exception.BusinessException;


import java.io.File;

/**
 * @BelongsProject: code-generation-platform
 * @BelongsPackage: com.gel.codegeneration.core.saver
 * @Author: gel
 * @CreateTime: 2025-08-22  16:04
 * @Description: TODO html代码保存模板
 * @Version: 1.0
 */
public class HtmlCodeFileSaveTemplate extends  CodeFileSaveTemplate<HtmlCodeResult>{
    @Override
    protected CodeGenTypeEnum getCodeType() {
        return CodeGenTypeEnum.HTML;
    }

    @Override
    protected void saveFile(HtmlCodeResult htmlCodeResult, String dirPath) {
        writeFile(htmlCodeResult.getHtmlCode(), dirPath, "index.html");
    }
    @Override
    protected void validateInput(HtmlCodeResult htmlCodeResult) {
        super.validateInput(htmlCodeResult);
        if(StrUtil.isBlank(htmlCodeResult.getHtmlCode())){
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"HTML代码内容不能为空");
        }
    }
}
